using AutoMapper;
using hao_Common.AutoMapper.Services;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;

namespace hao_Common.AutoMapper.Extensions
{
    /// <summary>
    /// AutoMapper 服务注册扩展
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 添加 AutoMapper 服务
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <param name="assemblies">包含 Profile 的程序集</param>
        /// <returns></returns>
        public static IServiceCollection AddAutoMapperService(this IServiceCollection services, params Assembly[] assemblies)
        {
            // 注册 AutoMapper
            services.AddAutoMapper(assemblies);
            
            // 注册映射服务
            services.AddScoped<IMapperService, MapperService>();
            
            return services;
        }
        
        /// <summary>
        /// 添加 AutoMapper 服务（自动扫描当前程序集）
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <returns></returns>
        public static IServiceCollection AddAutoMapperService(this IServiceCollection services)
        {
            return services.AddAutoMapperService(Assembly.GetCallingAssembly());
        }
    }
}